#ifndef __BENC_H__
#define __BENC_H__

#define MAX_ELEM	100 

typedef enum _benc_type{
	BENC_INTEGER = 1,
	BENC_STRING,
	BENC_LIST,
	BENC_DICT,
}benc_type;

typedef struct _benc{
	benc_type		type;

	union{
		int				  integer;
		char			 *string;
		struct _benc	**b_elems;	// each element in dict(list) is a b_elem, not include sub elements
	};
}benc;

int benc_metafile(char *buffer, int buff_len, benc *dict, unsigned char *hash_str);

int benc_integer(char *buffer, int buff_len, int *use_len, benc *intg);

int benc_string	(char *buffer, int buff_len, int *use_len, benc *str);

int benc_list	(char *buffer, int buff_len, int *use_len, benc *list);

int benc_dict	(char *buffer, int buff_len, int *use_len, benc *dict);

int free_string	(benc *string);

int free_list	(benc *list);

int free_dict	(benc *dict);

int get_benc_info(const char * const key, benc_type type, benc *dict, void *info); 
#endif
